<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <link  rel="stylesheet" type="text/css" href="../css/ostrich/tab1.css" />
   <%@include file="/view/resource.jsp" %>
  </head>
  <body class="easyui-layout">
  	 <!-- Search panel start -->
 	 <div class="ui-search-panel" region="north" style="height: 80px;" title="过滤条件" data-options="striped: false,collapsible:false,iconCls:'icon-search',border:false" >   
 	 <form id="searchForm">
 	 	<input class="hidden" id='search_parentId' name="parentId">
 	 	<p class="ui-fields">
            <label class="ui-label">请选择项目:</label> 
            <span id="projectselect"></span>
        </p>
        <a id="btn-search" class="easyui-linkbutton" iconCls="icon-search">查询</a>
        &nbsp;
        <input type="button" onclick="add()" value="添加数据">
        <script type="text/javascript">
        function add(){
        	var sel = document.getElementById("pjId");
        	var index = sel.selectedIndex;
        	var pjId = sel.value;
        	var pjName = sel.options[index].text;
        	if(pjId==null||pjId==""||pjName==null||pjName=="")
        		alert("请选择项目");
        	else
        		openAdd(pjId,pjName);
        }
        </script>
      </form>
     </div>
     <!--  Search panel end -->
     <!-- DataList  -->
	 <div region="center" border="false" >
     	<table id="data-list" border="0" width="80%"></table>
     </div>
     
     <!-- Edit Win&From -->
     <div id="edit-win" class="easyui-dialog" title="添加" data-options="closed:true,iconCls:'icon-save',modal:true"  style="width:1000px;height:350px;">  
     	<form id="editForm" name="editForm" action="save.do" method="post">
     	 <!-- 隐藏文本框 -->
     	 <table>
     	 <tr class="tabhead">
     	 	<td colspan="9" align="center" id="pj"></td>
     	 </tr>
     	 <tr>
     	 	<td colspan="3" align="center"></td>
     	 	<td colspan="4" align="center" >基础提成</td>
     	 	<td colspan="2" align="center">奖励提成</td>
     	 </tr>
     	 <tr>
     	 	<td width="15%" align="center">部门</td>
     	 	<td width="10%" align="center">类型</td>
     	 	<td width="10%" align="center">提成节点</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_1" class="easyui-combobox" style="width:95%; border: 1px solid #ccc" ></select>
     	 	</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_2" class="easyui-combobox" style="width:95%; border: 1px solid #ccc" ></select>
     	 	</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_3" class="easyui-combobox" style="width:95%; border: 1px solid #ccc"></select>
     	 	</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_4" class="easyui-combobox" style="width:95%; border: 1px solid #ccc"></select>
     	 	</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_5" class="easyui-combobox" style="width:95%; border: 1px solid #ccc"></select>
     	 	</td>
     	 	<td width="10%" align="center">
     	 		<select  id="td1_6" class="easyui-combobox" style="width:95%; border: 1px solid #ccc"></select>
     	 	</td>
     	 </tr>
     	 <tr>
     	 	<td rowspan="4" align="center">
     	 		<select id="depart1" ></select>
     	 	</td>
     	 	<td rowspan="4" align="center">
     	 		<select id="pdyType1"></select>
     	 	</td>
     	 	<td align="center">是否提取</td>
     	 	<td align="center">
     	 		<select id="td2_1">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 	<td align="center">
     	 		<select id="td2_2">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 	<td align="center">
     	 		<select id="td2_3">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 	<td align="center">
     	 		<select id="td2_4">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 	<td align="center">
     	 		<select id="td2_5">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 	<td align="center">
     	 		<select id="td2_6">
     	 			<option value="true">是</option>
     	 			<option value="false">否</option>
     	 		</select>
     	 	</td>
     	 <tr>
     	 	<td align="center">提取金额</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_1" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_2" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_3" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_4" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_5" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td3_6" style="width:90%">
     	 	</td>
     	 </tr>
     	 <tr>
     	 	<td align="center">提取时间</td>
     	 	<td align='center'>
     	 		<input type="text" id="td4_1" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td4_2" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td4_3" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td4_4" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td4_5" style="width:90%">
     	 	</td>
     	 	<td align="center">
     	 		<input type="text" id="td4_6" style="width:90%">
     	 	</td>
     	 </tr>
     	 <tr>
     	 	<td align="center">备注</td>
     	 	<td colspan="6" align="center">
     	 		<input type="text" id="pdyDesc" name="pdyDesc" style="width:90%">
     	 	</td>
     	 </tr>
     	 </table>
     	 <div style="color: red;">注意：如需合并，请在前项输入+号即可。数据会以+号后的数据为合并后的值。</div>
     	 <div align="center" ><a id="btn-search" class="easyui-linkbutton" iconCls="icon-search" onclick="sub()">确定添加</a></div>
     	 <input type="hidden" id="id" name="id">
     	 <input type="hidden" id="projid" name="pjId">
     	 <input type="hidden" id="pjName" name="pjName">
     	 <input type="hidden" id="hdpId" name="hdpId">
     	 <input type="hidden" id="hdpName" name="hdpName">
     	 <input type="hidden" id="pdyType" name="pdyType">
     	 <input type="hidden" id="pdyBppoint" name="pdyBppoint">
     	 <input type="hidden" id="pdyBpisextract" name="pdyBpisextract">
     	 <input type="hidden" id="pdyBpextractmoney" name="pdyBpextractmoney">
     	 <input type="hidden" id="pdyBpextracttime" name="pdyBpextracttime">
     	 <input type="hidden" id="pdyAppoint" name="pdyAppoint">
     	 <input type="hidden" id="pdyApisextract" name="pdyApisextract">
     	 <input type="hidden" id="pdyApextractmoney" name="pdyApextractmoney">
     	 <input type="hidden" id="pdyApextracttime" name="pdyApextracttime">
     	</form>
     	<script type="text/javascript">
     	function openAdd(pjId,pjname){
			$('#edit-win').dialog('open');
			document.getElementById("pj").innerHTML=pjname;
			document.getElementById("projid").value=pjId;
			document.getElementById("pjName").value=pjname;
		}
		
		function sub(){
		var pdyBppoint="";
		var pdyBpisextract="";
		var pdyBpextractmoney="";
		var pdyBpextracttime="";
		var pdyApextractmoney="";
		var pdyApextracttime="";
		var pdyAppoint="";
		var pdyApisextract="";
			for(var i=1;i<=4;i++){
				for(var j=1;j<=6;j++){
					if(i==1&&j<=4){
						if(j<4)
							pdyBppoint+=$("#td"+i+"_"+j).combobox("getText")+"|";
						if(j==4)
							pdyBppoint+=$("#td"+i+"_"+j).combobox("getText");
					}
					if(i==1&&j>=5){
						if(j==5)
							pdyAppoint+=$("#td"+i+"_"+j).combobox("getText")+"|";
						if(j==6)
							pdyAppoint+=$("#td"+i+"_"+j).combobox("getText");
					}
					
					if(i==2&&j<=4){
						if(j<4)
							pdyBpisextract+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==4)
							pdyBpisextract+=document.getElementById("td"+i+"_"+j).value;
					}
					if(i==2&&j>=5){
						if(j==5)
							pdyApisextract+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==6)
							pdyApisextract+=document.getElementById("td"+i+"_"+j).value;
					}
					
					if(i==3&&j<=4){
						if(j<4)
							pdyBpextractmoney+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==4)
							pdyBpextractmoney+=document.getElementById("td"+i+"_"+j).value;
					}
					if(i==3&&j>=5){
						if(j==5)
							pdyApextractmoney+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==6)
							pdyApextractmoney+=document.getElementById("td"+i+"_"+j).value;
					}
					
					if(i==4&&j<=4){
						if(j<4)
							pdyBpextracttime+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==4)
							pdyBpextracttime+=document.getElementById("td"+i+"_"+j).value;
					}
					if(i==4&&j>=5){
						if(j==5)
							pdyApextracttime+=document.getElementById("td"+i+"_"+j).value+"|";
						if(j==6)
							pdyApextracttime+=document.getElementById("td"+i+"_"+j).value;
					}
				}
			}
		document.getElementById("pdyBppoint").value=pdyBppoint;
		document.getElementById("pdyBpisextract").value=pdyBpisextract;
		document.getElementById("pdyBpextractmoney").value=pdyBpextractmoney;
		document.getElementById("pdyBpextracttime").value=pdyBpextracttime;
		document.getElementById("pdyAppoint").value=pdyAppoint;
		document.getElementById("pdyApisextract").value=pdyApisextract;
		document.getElementById("pdyApextractmoney").value=pdyBpextractmoney;
		document.getElementById("pdyApextracttime").value=pdyBpextracttime;
		document.getElementById("pdyType").value=document.getElementById("pdyType1").value;
			var selectIndex = document.getElementById("depart1").selectedIndex;
			var selectText = document.getElementById("depart1").options[selectIndex].text;
			var selectvalue = document.getElementById("depart1").options[selectIndex].value;
		document.getElementById("hdpName").value=selectText;
		document.getElementById("hdpId").value=selectvalue;
		document.editForm.submit();
		alert("操作成功！");
		}
		
		function loadData(depart,pdytype,databp,dataap){
		
			var strDepart = "";
			for(var t=0;t<depart.length;t++){
					strDepart += "<option value='"+depart[t].id+"'>"+depart[t].hdpName+"</option>";
				}
				document.getElementById("depart1").innerHTML=strDepart;
				
			var strpdyType = "";
			for(var r=0;r<pdytype.length;r++){
					strpdyType += "<option value='"+pdytype[r].paValue+" '>"+pdytype[r].paName+"</option>";
				}
			document.getElementById("pdyType1").innerHTML=strpdyType;
			
			for(var i=1;i<=4;i++){
				$("#td1_"+i).combobox({
					data:databp,
					cache: true,  //tostHrDepartinfo/getDepartBypost  tostHrBaseinfo
				    // panelHeight: 'auto',//自动高度适合    去掉，显示滚动条
					dataType:'json',
					valueField:'id',
					textField:'paName',
					multiple:false,
					async:false,
					formatter:function(resultf){
						var s= "<span><input type='hidden' class='selectId' style='vertical-align: middle' id='selectId_"+resultf.id+"' value='"+resultf.paName+"'>"+resultf.paName+"</span>";
						return s;
					},
					onSelect:function(result){
						$("#selectId_"+result.id).attr("checked", true);
					},
					onUnselect:function(result){
						$("#selectId_"+result.id).attr("checked", false);
					},
				});
			}
			
			for(var i=5;i<=6;i++){
				$("#td1_"+i).combobox({
					data:dataap,
					cache: true,  //tostHrDepartinfo/getDepartBypost  tostHrBaseinfo
				    // panelHeight: 'auto',//自动高度适合    去掉，显示滚动条
					dataType:'json',
					valueField:'id',
					textField:'paName',
					multiple:false,
					async:false,
					formatter:function(resultf){
						var s= "<span><input type='hidden' class='selectId' style='vertical-align: middle' id='selectId_"+resultf.id+"' value='"+resultf.paName+"'>"+resultf.paName+"</span>";
						return s;
					},
					onSelect:function(result){
						$("#selectId_"+result.id).attr("checked", true);
					},
					onUnselect:function(result){
						$("#selectId_"+result.id).attr("checked", false);
					},
				});
			}
		}
		
		function onHdpType(i){
			document.getElementById("pdyType").value=document.getElementById("pdyType_"+i).value;
		}
		function onHdpId(i){
			var selectIndex = document.getElementById("hdpId_"+i).selectedIndex;
			var selectText = document.getElementById("hdpId_"+i).options[selectIndex].text;
			var selectvalue = document.getElementById("hdpId_"+i).options[selectIndex].value;
		document.getElementById("hdpName").value=selectText;
		document.getElementById("hdpId").value=selectvalue;
		}
		function onBpIs(i,u,bpis){
		
		var oldValue = document.getElementById("pdyBpisextract").value;
		if(oldValue==null||oldValue==undefined||oldValue==""){
			oldValue=bpis;
		}
		var stbp1 = oldValue.split("|");
		var bpisvalue = document.getElementById("bpis_"+i+"_"+u).value;
			switch(u){
			case 0:document.getElementById("pdyBpisextract").value=bpisvalue+"|"+stbp1[1]+"|"+stbp1[2]+"|"+stbp1[3];
				break;
			case 1:document.getElementById("pdyBpisextract").value=stbp1[0]+"|"+bpisvalue+"|"+stbp1[2]+"|"+stbp1[3];
				break;
			case 2:document.getElementById("pdyBpisextract").value=stbp1[0]+"|"+stbp1[1]+"|"+bpisvalue+"|"+stbp1[3];
				break;
			case 3:document.getElementById("pdyBpisextract").value=stbp1[0]+"|"+stbp1[1]+"|"+stbp1[2]+"|"+bpisvalue;
				break;
			}
		}
		
		function onApIs(i,v,apis){
		
		var apisvalue = document.getElementById("apis_"+i+"_"+v).value;
		var oldValue = document.getElementById("pdyApisextract").value;
		if(oldValue==null||oldValue==undefined||oldValue==""){
			oldValue=apis;
		}
		var stap1 = oldValue.split("|");
			switch(v){
			case 0:document.getElementById("pdyApisextract").value=apisvalue+"|"+stap1[1];
				break;
			case 1:document.getElementById("pdyApisextract").value=stap1[0]+"|"+apisvalue;
				break;
			}
		}
		
		function subSave(id,pjId,pjName){
			document.getElementById("id").value=id;
			document.getElementById("projid").value=pjId;
			document.getElementById("pjName").value=pjName;
			document.editForm.submit();
		}
		
		function del(id){
			$.ajax({
				url:"deleteById.do",
				dataType:'json',
				data:[{name:'id',value:id}],
				success:function (result){
					location.href="list.do";
				}
			});
		}
     	</script>
  	 </div>
  <script type="text/javascript" src="<%=basePath%>/osjs/project/TostPjDepartpushmoney.js"></script>
  </body>
</html>